import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import login from '../views/login.vue'
import index from '../views/index.vue'
import bumen from '../views/bumen'
import chengshi from '../views/chengshi'
import fuwu from '../views/fuwu'
import hexin from '../views/hexin'
import zhineng from '../views/zhineng'
import xiaozu from '../views/xiaozu'
import renyuan from '../views/renyuan'
import wenjuan from '../views/wenjuan'
import lishi from '../views/lishi/'
import tongji from '../views/tongji'
import personnel from '../views/personnel/'
import answer from '../views/personnel/answer'
import answers from '../views/personnel/answers'
import questionnaire from '../views/wenjuan/questionnaire'
 

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect: '/bumen' // 默认连接
  },
  {
    path: '/',
    component: index,
    children: [
    //   {
    //   path: '/Home',
    //   name: '主页',
    //   component: Home,
    //   meta: { title: '主页' }
    // }, 
    {
      path: '/bumen',
      name: '部门管理',
      component: bumen,
      meta: { title: '部门管理' }
    }, {
      path: '/chengshi',
      name: '城市公司管理',
      component: chengshi,
      meta: { title: '城市公司管理' }
    }, {
      path: '/fuwu',
      name: '服务质量管理',
      component: fuwu,
      meta: { title: '服务质量管理' }
    }, {
      path: '/hexin',
      name: '核心工作管理',
      component: hexin,
      meta: { title: '核心工作管理' }
    }, {
      path: '/zhineng',
      name: '职能互评管理',
      component: zhineng,
      meta: { title: '职能互评管理' }
    }, {
      path: '/xiaozu',
      name: '小组配置',
      component: xiaozu,
      meta: { title: '小组配置' }
    },
    {
      path: '/xiaozupingce',
      name: '小组测评配置',
      component: xiaozu,
      meta: { title: '小组测评管理' }
    }, 
    {
      path: '/renyuan',
      name: '人员配置管理',
      component: renyuan,
      meta: { title: '人员配置管理' }
    }, {
      path: '/wenjuan',
      name: '问卷配置管理',
      component: wenjuan,
      meta: { title: '问卷配置管理' }
    }, {
      path: '/lishi',
      name: '问卷评价历史',
      component: lishi,
      meta: { title: '问卷评价历史' }
    }, {
      path: '/tongji',
      name: '问卷评价统计',
      component: tongji,
      meta: { title: '问卷评价统计' }
    }]
  },{
    path: '/personnel',
    name: '人员',
    component: personnel,
    meta: { title: '人员' }
  },{
    path: '/answer',
    name: '人员答题',
    component: answer,
    meta: { title: '人员答题' }
  },{
    path: '/answers',
    name: '人员答题',
    component: answers,
    meta: { title: '人员答题' }
  },{
    path: '/questionnaire',
    name: '问卷配置',
    component: questionnaire,
    meta: { title: '问卷配置' }
  }, {
    path: '/login',
    name: '登陆',
    component: login,
    meta: { title: '登陆' }
  }
]

const router = new VueRouter({
  // mode: 'history',
  // base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,form,next)=>{
  if(to.path==='/login'){
    return next();
  }
  let user = localStorage.getItem("userinfo");
  if(user==null){
    return next('/login')
  }
  let userinfo = JSON.parse(user);
  if(userinfo.role=="4" && to.path!="/questionnaire"){
    localStorage.removeItem("token");
    localStorage.removeItem("userinfo");
    return next('/login')
  }
  next();
})

export default router
